<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="6" :xs="20" style="border-right: solid 1px #324157">
                <el-form :model="examParams" ref="examForm" size="mini" :inline="true" label-width="48px">
                    <el-form-item label="名称" prop="name">
                        <el-input v-model="examParams.name" placeholder="请输入考试名称" clearable @keyup.enter.native="examQuery"/>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="success" size="mini" plain @click="examQuery" v-hasPermi="['score:performance:list']">搜索</el-button>
                        <el-button size="mini" plain @click="examResetQuery" v-hasPermi="['score:performance:list']">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-table v-loading="exam_loading" :data="score_ex_examList" size="mini" :height="table_height" @row-dblclick="changeSelectExam">
                    <el-table-column label="名称" align="center" prop="name"/>
                    <el-table-column label="考试日期" align="center" width="176px">
                        <template slot-scope="scope">
                            <el-tag size="small" effect="plain" v-if="scope.row.exStartDate === scope.row.exEndDate">
                                {{ scope.row.exStartDate }}
                            </el-tag>
                            <template v-else>
                                <el-tag size="small" type="success" effect="plain">{{ scope.row.exStartDate }} ~ {{ scope.row.exEndDate }}</el-tag>
                            </template>
                        </template>
                    </el-table-column>
                </el-table>
                <pagination v-show="exam_total>0" :total="exam_total" :page.sync="examParams.pageNum" :limit.sync="examParams.pageSize" @pagination="getExamList"/>
            </el-col>
            <el-col :span="18" :xs="20">
                <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                         label-width="68px">
                    <el-form-item>
                        <el-tag type="warning" effect="plain">{{examName == null ? '未选择' : examName}}</el-tag>
                    </el-form-item>
                    <el-form-item label="用户名称" prop="nickName">
                        <el-input v-model="queryParams.nickName" placeholder="请输入用户名称" clearable @keyup.enter.native="handleQuery"/>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['face:face_record:remove']">删除</el-button>
                    </el-col>
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>

                <el-table v-loading="loading" :data="face_recordList" @selection-change="handleSelectionChange" :height="table_height">
                    <el-table-column type="selection" width="55" align="center"/>
                    <el-table-column label="用户" align="center" prop="nickName"  width="100"/>
                    <el-table-column label="识别详情" align="center" prop="info">
                        <template slot-scope="scope">
                            <span v-html="scope.row.info"></span>
                        </template>
                    </el-table-column>
                    <el-table-column label="识别时间" align="center" prop="createTime"  width="180">
                        <template slot-scope="scope">
                            {{parseTime(scope.row.createTime)}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['face:face_record:remove']">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import {
    listFace_record,
    getFace_record,
    delFace_record,
    addFace_record,
    updateFace_record
} from "@/api/face/face_record";
import {nowDateStr} from "@/utils/zzDouUtils/dateUtil";
import {listScore_ex_exam} from "@/api/score/score_ex_exam";

export default {
    name: "Face_record",
    data() {
        return {
            exam_loading: false,
            score_ex_examList: [],
            exam_total: 0,
            examParams: {// 查询参数
                pageNum: 1,
                pageSize: 10,
                name: null,
            },
            examName:null,
            //-----------------
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 人脸识别记录表格数据
            face_recordList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 预留字段2时间范围
            daterangeCreateTime: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                userId: null,
                placeId: null,
                info: null,
                reservedOne: null,
                reservedTwo: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {}
        };
    },
    created() {
        this.getExamList();
    },
    methods: {
        /** 获取考试列表 */
        getExamList() {
            this.exam_loading = true;
            listScore_ex_exam(this.examParams).then(response => {
                this.score_ex_examList = response.rows;
                this.exam_total = response.total;
                this.exam_loading = false;
            });
        },
        examQuery() {
            this.examParams.pageNum = 1;
            this.getExamList();
        },
        examResetQuery() {
            this.resetForm("examForm");
            this.examQuery();
        },
        changeSelectExam(row) {
            this.examName = row.name;
            this.queryParams.examId = row.id;
            this.getList();
        },
        //--------------------------
        /** 查询人脸识别记录列表 */
        getList() {
            this.loading = true;
            this.queryParams.params = {};
            if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
                this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
                this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
            }
            listFace_record(this.queryParams).then(response => {
                this.face_recordList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.daterangeCreateTime = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除人脸识别记录编号为"' + ids + '"的数据项？').then(function () {
                return delFace_record(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('face/face_record/export', {
                ...this.queryParams
            }, `face_record_${nowDateStr()}.xlsx`)
        }
    }
};
</script>
